using System;

namespace MetaObjects.Core
{
	public static class MapperExtensions
	{
		public static Mapper<TSource, TTarget> WithConstructor<TSource, TTarget>(this Mapper<TSource, TTarget> testMapper, Func<TTarget> ctor)
		{
			Func<TSource, TTarget> map = s => ctor();
			return new Mapper<TSource, TTarget>(map);
		}

		public static Mapper<TSource, TTarget> AddAction<TSource, TTarget>(this Mapper<TSource, TTarget> testMapper, Action<TSource, TTarget> action)
		{
			Func<TSource, TTarget> map = s => ApplyAction(s, testMapper.Map(s), action);
			return new Mapper<TSource, TTarget>(map);
		}

		public static TTarget ApplyAction<TSource, TTarget>(TSource s, TTarget d, Action<TSource, TTarget> action)
		{
			action(s, d);
			return d;
		}
	}
}